{
    gROOT->Reset();
    
    // 	TFile f("out_dkl.root");
	TFile f("../src/out.root");
//     TFile f("out_meas1-pedestal.root");
// 	TCanvas MyCanvas ("test1");
    int tdelta	= 33000;
    int tcenter	= 16500;
    
    int cut_time = 50;
    int rebin    = 2;
    
    TCanvas *canvas1;
    TLegend *legend;
    TH1F *h10,*h11,*h12;
    
    
    int qdc_choice[] = {1,0}; // { "#Detector" , "#QDC" }
//     int qdc_choice[] = {2,3}; // { "#Detector" , "#QDC" }
//     int qdc_choice[] = {3,1}; // { "#Detector" , "#QDC" }
    
    int PM_MIN  = qdc_choice[1];
    int DET_MIN = qdc_choice[0];
    int ped = 0;

//     stringstream smax,s0,s1,s2,title;
        
//     for (ped = 0; ped < 3; ped++) {
//         qdc_choice[] = {1,ped}; // { "#Detector" , "#QDC" }
//         PM_MIN  = ped;
        
    stringstream smax,s0,s1,s2,title;
    
    canvas1 = new TCanvas("canvas1","canvas1",1);
	canvas1.SetFillColor(10);
	canvas1.SetFrameFillColor(10);
// 	TLegend *legend = new TLegend(.70,.60,.95,.95,"legend");
    legend = new TLegend(.70,.60,.95,.95,"legend");

    
    
    hmax=new TH1F("hmax","hmax", tdelta, (tcenter-tdelta/2), (tcenter+tdelta/2));
    smax << "Det" << DET_MIN << "[" << PM_MIN << "] >> hmax";
    Data->Draw(smax.str().c_str());
    
//     tcenter = (tcenter-tdelta/2)+hmax->GetMaximumBin();
// 	tcenter = 1850;
//     cout<<"tcenter="<<tcenter<<endl;
//     tdelta  = 250;
//     tdelta  = 1000;
//     tdelta  = 500;

//     tdelta  = 2 * tcenter;

    if (tdelta > tcenter*2)
        tdelta = tcenter*2;
//     tcenter=1500;

	s0 << "Det" << DET_MIN << "[" << PM_MIN << "] >> h10";
	s1 << "Det" << DET_MIN << "[" << PM_MIN << "] >> h11";
	s2 << "Det" << DET_MIN << "[" << PM_MIN << "] >> h12";
	title << "Det" << DET_MIN << "[" << PM_MIN << "]";
	cout << title.str() << endl;
	
	h10=new TH1F("h10",title.str().c_str(), tdelta, (tcenter-tdelta/2), (tcenter+tdelta/2));
	h11=new TH1F("h11",title.str().c_str(), tdelta, (tcenter-tdelta/2), (tcenter+tdelta/2));
	h12=new TH1F("h12",title.str().c_str(), tdelta, (tcenter-tdelta/2), (tcenter+tdelta/2));

	h10->SetLineColor(1);
	h11->SetLineColor(2);
	h12->SetLineColor(3);

	
// 	Data->Draw("Det1[1] >> h10");
// 	Data->Draw("Det1[1] >> h11" , "DeltaTimerCounter <= 50 ");
// 	Data->Draw("Det1[1] >> h12" , "DeltaTimerCounter > 50 ");
// 	Data->Draw(s0.str().c_str() ,"Det2[5]<2500");
    
    Data->Draw(s0.str().c_str());
//     Data->Draw(s0.str().c_str(),"Valid == 1");

    stringstream lowcut, highcut;
    lowcut  << "DeltaTime <= " << cut_time;
    highcut << "DeltaTime >  " << cut_time;

    Data->Draw( s1.str().c_str() ,  lowcut.str().c_str() );
    Data->Draw( s2.str().c_str() , highcut.str().c_str() );
    h10.Rebin(rebin);
    h11.Rebin(rebin);
    h12.Rebin(rebin);

//     h10->GetYaxis()->SetRangeUser(0, 10000*rebin);
	

    
    h10->Draw();
	h11->Draw("same");
    h12->Draw("same");
    
    Double_t par0[3],par1[3],par2[3];
    
//     TF1 *fit0 = new TF1("fit0","gaus");
    TF1 *fit1 = new TF1("fit1","gaus");
    TF1 *fit2 = new TF1("fit2","gaus");
    
//     h10->Fit(fit0,"W");
    h11->Fit(fit1,"W","same");
    h12->Fit(fit2,"W","same");
    
//     fit0->GetParameters(&par0[0]);
    fit1->GetParameters(&par1[0]);
    fit2->GetParameters(&par2[0]);
    
    cout << "\n\nDelta E between the 2 gauss " << (int) (par2[1]-par1[1]+0.5) << " CH" << endl;
    
// 	canvas1->SetLogy();
}
// }
